home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT8 / GOTOXY.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-08-27  |  4.7 KB  |  105 lines

  1. ;
  2. ;       Program GotoXY ( Chapter 8 )
  3. ;
  4. page    55,132
  5. ;       
  6. ;       cursor moving program   version 1.2   26.05.1992
  7. ;       copyright (C) V.B.Maljugin  1992  Voronezh,  Russia
  8. ;       
  9. .model SMALL                    ; this defines memory model
  10. .stack
  11. .data                           ; this starts DATA segment
  12. Factor  dw      0               ;
  13. ten     dw      10              ;
  14. X       db      0               ; number of ROW on screen
  15. Y       db      0               ; number of COLUMN on screen
  16. .code                           ; this starts CODE segment
  17. ;===    block0 - start the program
  18. .startup
  19. ;===    block 1 - prepare to work
  20.         mov     cx,0            ; clear cycle counter
  21.         mov     cl,es:80h       ; set counter to parameter string length
  22.         inc     cl              ; CX points to first character
  23.         mov     ax,es           ; we can't process ES content directly
  24.         add     ax,8h           ; ES now points to parameter string
  25.         mov     es,ax           ; set new ES content
  26.         mov     bx,0            ; BX points to start of parameter string
  27. ;===    block 2 - read an X coordinate from parameter string
  28.         call    SkipBlank       ; skip blank characters
  29.         call    ReadNext        ; read next number
  30.         mov     X,al            ; store ROW number (X)
  31. ;===    block 3 - read a Y coordinate from parameter string
  32.         call    SkipBlank       ; skip blank characters
  33.         call    ReadNext        ; read next number
  34.         mov     Y,al            ; store COLUMN number (Y)
  35. ;===    block 4 - check whether coordinates are non-zero
  36.         add     al,X            ; add X and Y coordinates
  37.         cmp     al,0            ; sum X+Y is 0 when both X and Y are 0
  38.         je      Finish          ; if X and Y are 0 - exit
  39. ;===    block 5 - move cursor into a new position                   
  40.         mov     ax,40h          ; segment address of BIOS data area
  41.         mov     es,ax           ; ES points to BIOS data area
  42.         mov     bh,es:62h       ; [462] - active video page number
  43.         mov     dh,X            ; DH - ROW on screen
  44.         mov     dl,Y            ; DL - COLUMN on screen
  45.         mov     ah,2            ; function 02h - move cursor
  46.         int     10h             ; BIOS video service
  47. ;===    block 6 - exit program
  48. Finish:                         ;
  49.         mov     ax,4C00h        ; function 4Ch - terminate process
  50.         int     21h             ; Dos service call
  51. ;
  52. ;       =============  work procedures  =================
  53. ;
  54. SkipBlank       proc    near
  55. ;       this procedure scans parameter string and skips blank characters
  56. ;       
  57. ;       parameters on entry:
  58. ;       BX - offset of current character
  59. ;       DL - a first digit character (if any) or last character of the string
  60. ;
  61. GetS:   inc     bx              ; BX will point to next character
  62.         mov     dl,es:[bx]      ; get current character into DL
  63.         cmp     cx,bx           ; is that end of parameter string?
  64.         jl      AllParm         ; if so - process the accepted values
  65.         cmp     dl,30h          ; current character less than 0?
  66.         jl      GetS            ; if so - get next character
  67.         cmp     dl,39h          ; current character greater than 9?
  68.         ja      GetS            ; if so - get next character
  69. AllParm:
  70.         ret
  71. SkipBlank       endp
  72.  
  73. ReadNext        proc    near
  74. ;
  75. ;       this procedure reads a parameter from command line
  76. ;       and transfers it to numeric form
  77. ;
  78. ;       parameters on entry:
  79. ;       DL - current character
  80. ;       BX - offset of current character from beginning of string
  81. ;       CX - maximum number of characters in string (length of string)
  82. ;       ES - segment address of parameter string in PSP ( Seg PSP + 8 )
  83. ;
  84. ;       result will be returned in AL 
  85. ;
  86.         mov     ax,0
  87. ProcSym:
  88.         cmp     dl,30h          ; current character less than 0?
  89.         jl      EndNext         ; if so - stop the process
  90.         cmp     dl,39h          ; current character greater than 9?
  91.         ja      EndNext         ; if so - stop process
  92.         sub     dl,30h          ; transform character into 8-bit integer
  93.         mov     Factor,dx       ; store that integer
  94.         mul     ten             ; multiply AX by 10
  95.         add     ax,Factor       ; add current character (as integer)
  96.         mov     dx,0            ; prepare DX for processing next character
  97.         inc     bx              ; increase character's counter
  98.         mov     dl,es:[bx]      ; read next character into DL
  99.         cmp     bx,cx           ; is that end of parameter string?
  100.         jl      ProcSym         ; if not - process current character
  101. EndNext:                        ;
  102.          ret
  103. ReadNext        endp
  104.         end
  105.